<template>
  <div class="service-time-wrap">
    <p class="msg-warn"><span class="iconfont icon-xinxi-mian"></span>如果设置多个时间，优先级为特殊工作时间>节假日>常规工作时间，例如在五一假期设置第一天为值班日；工作时间（常规工作+特殊工作）以外都属于非服务时间，包括节假日。</p>
    <div class="clearfix">
      <el-form :model="form" class="fl" label-position="top" label-width="100px" @submit.native.prevent>
        <el-form-item label="服务时间名称" prop="name">
          <el-input size="mini" style="width:220px;" v-model="form.name" @keyup.enter.native="onFetchData" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <div class="fr btn-wrap">
        <el-button size="mini" @click="onFetchData">查询</el-button>
        <el-button size="mini" type="primary" @click="onAdd">新建</el-button>
      </div>
    </div>
     <el-table :data="tableData" :highlight-current-row="true" :stripe="true" :border="true" size="mini">
      <template v-for="item in headers">
        <el-table-column
          :key="item.prop"
          v-if="item.prop !== 'oprate'"
          :prop="item.prop"
          :label="item.label">
        </el-table-column>
        <el-table-column
          :key="item.prop"
          v-if="item.prop === 'oprate'"
          :prop="item.prop"
          :label="item.label">
          <template scope="scope">
            <span class="edit" @click="onEdit(scope.row)">{{$t('public.edit')}}</span>
          </template>
      </el-table-column>
      </template>
    </el-table>
    <div class="clearfix pagination-box">
      <el-pagination
      class="fr"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagingData.page"
      :page-sizes="[10, 20, 50]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagingData.total || 0">
    </el-pagination>
    </div>
    <add-service-time ref="AddServiceTime" @onRefresh="onFetchData"></add-service-time>
  </div>
</template>
  
  <script>
  import addServiceTime from './addTime.vue'
  import getServiceTimeList from './addTime.vue'
  export default {
    name: 'ServiceTime',
    components: { addServiceTime },
    data () {
      return {
        // 检索表单
        form: { name: '' },
        // 表格数据
        tableData: [],
        // 表头数据
        headers: [
          { label: '服务时间名称', prop: 'name', show: true },
          { label: '最后更新时间', prop: 'updateTime', show: true },
          { label: '操作', prop: 'oprate', show: true }
        ],
        // 分页数据
        pagingData: { page: 1, total: 0, limit: 10 }
      }
    },
    methods: {
      searchFun(){
        this.pagingData.page = 1
        this.onFetchData()
      },
       // 新建服务时间
      onAdd(){
        this.$refs.AddServiceTime.openDialog('add')
      },
      // 编辑服务时间
      onEdit(data){
        this.$refs.AddServiceTime.openDialog('edit', data || {})
      },
      // 获取服务时间列表
      onFetchData () {
        const sendData = {
          ...this.form,
          limit: this.pagingData.limit,
          page: this.pagingData.page
        }
        this.$store.dispatch('getServiceTimeList', sendData).then((res) => {
          if (res.success) {
            this.tableData = res.data || []
            this.pagingData.total = res.count || 0
          }
        })
      },
      handleCurrentChange (page) {
        this.pagingData.page = page
        this.onFetchData()
      },
      handleSizeChange(size){
        this.pagingData.limit = size
        this.onFetchData()
      }
    },
    beforeMount() {
      this.onFetchData()
    }
  }
  </script>
    <!--  -->
<style lang="stylus" scoped>
  @import "../../../../assets/common.styl"
  .edit
    color $c-main
    cursor pointer
  .icon-xinxi-mian
    color $c-main
    padding-right 10px
   
  .service-time-wrap
    overflow auto
    padding 20px
    height 100%
    .btn-wrap
       margin-top 24px
    .pagination-box
      margin 20px auto
      .el-pagination
        margin-bottom 20px
    .msg-warn
      margin-bottom 16px
      font-size 12px
      color rgba(0,0,0,.88)
      display flex
      align-items center
      padding 8px 24px 8px 20px
      border-radius 4px
      background rgba(28, 97, 241, 0.1)
    .clearfix:after
      display block
</style>
  